<?php 
namespace Admin\Model;
use Think\Model\RelationModel;
class ArticleModel extends RelationModel{
	protected $_validate = array(
		array('title','require','添加失败:标题不能为空！'),
		array('cate_id','require','参数错误！'),
		array('user_id','require','参数错误！'),
	);
	protected $_link=array(
		'category' => array(
			'mapping_type'   => self::BELONGS_TO,
			'class_name'     => 'category',
			'foreign_key'    => 'cate_id',
			'mapping_fields' => 'name',
			'as_fields'      => 'name:cate',
		),
		'member' => array(
			'mapping_type'   => self::BELONGS_TO,
			'class_name'     => 'member',
			'foreign_key'    => 'user_id',
			'mapping_fields' => 'username',
			'as_fields'      => 'username:user',
		),
	);
	//获取文章
	public function getArticles($number,$where,$order){
		$count = $this->where($where)->count();
		$Page  = new \Library\Page($count,$number);// $number为分页数
		$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <li>%HEADER%</li>');
		$data['page'] = $Page->show();// 分页显示输出
		$data['article'] =
		       $this->where($where)
					->order($order)
					->limit($Page->firstRow.','.$Page->listRows)
					->relation(true)
					->select();
		return $data;
	}
}

 ?>